From: tsteven4 Date: Tue, 27 Nov 2018 23:37:49 +0000 (-0700) Subject: simplify conversion from utm. (#275) X-Git-Tag: archive/raspbian/1.10.0+ds-2+rpi1~1^2~12^2~8^2~66 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22%22/%22http:/www.example.com/cgi/%22https:/%22%22?a=commitdiff_plain;h=ceb82a4b60f7dce73d4f96fa84ec91d31efeab99;p=gpsbabel.git simplify conversion from utm. (#275) * simplify conversion from utm. add test cases for Norway and Svalbard exceptions. * Correct bug in computing latitude band X. enhance test to cover exceptional width of band X. --- diff --git a/jeeps/gpsmath.cc b/jeeps/gpsmath.cc index 944fec10d..b71654ae5 100644 --- a/jeeps/gpsmath.cc +++ b/jeeps/gpsmath.cc @@ -2004,19 +2004,19 @@ static int32 GPS_Math_LatLon_To_UTM_Param(double lat, double lon, int32* zone, { int32 ilon; int32 ilat; - int32 psign; - int32 lsign; + bool psign; + bool lsign; if (lat >= 84.0 || lat < -80.0) { return 0; } - psign = lsign = 0; + psign = lsign = false; if (lon < 0.0) { - lsign=1; + lsign=true; } if (lat < 0.0) { - psign=1; + psign=true; } ilon = abs((int32)lon); @@ -2024,10 +2024,10 @@ static int32 GPS_Math_LatLon_To_UTM_Param(double lat, double lon, int32* zone, if (!lsign) { *zone = 31 + (ilon / 6); - *Mc = (double)((ilon / 6) * 6 + 3); + *Mc = static_cast((ilon / 6) * 6 + 3); } else { *zone = 30 - (ilon / 6); - *Mc = -(double)((ilon / 6) * 6 + 3); + *Mc = -static_cast((ilon / 6) * 6 + 3); } if (!psign) { @@ -2042,14 +2042,19 @@ static int32 GPS_Math_LatLon_To_UTM_Param(double lat, double lon, int32* zone, } } + // The northernmost latitude band, X, is 12 degrees tall + // instead of the usual 8 degrees, i.e. [72.0,84.0). + if (*zc=='Y') { + *zc = 'X'; + } - if (lat>=56.0 && lat<64.0 && lon>=3.0 && - lon<12.0) { + // Norway exception + if (*zc=='V' && lon>=3.0 && lon<12.0) { *zone = 32; - *zc = 'V'; *Mc = 9.0; } + // Svalbard exception if (*zc=='X' && lon>=0.0 && lon<42.0) { if (lon<9.0) { *zone = 31; @@ -2169,32 +2174,14 @@ static int32 GPS_Math_UTM_Param_To_Mc(int32 zone, char zc, double* Mc, double* E0, double* N0, double* F0) { - if (zone>60 || zone<0 || zc<'C' || zc>'X') { + if (zone>60 || zone<0 || zc<'C' || zc>'X' || zc=='I' || zc=='O') { return 0; } - if (zone > 30) { - *Mc = (double)((zone-31)*6) + 3.0; - } else { - *Mc = (double) -(((30-zone)*6)+3); - } - - if (zone==32 && zc=='V') { - *Mc = 9.0; - } + *Mc = static_cast(((zone-31)*6) + 3); - if (zone==31 && zc=='X') { - *Mc = 3.0; - } - if (zone==33 && zc=='X') { - *Mc = 15.0; - } - if (zone==35 && zc=='X') { - *Mc = 27.0; - } - if (zone==37 && zc=='X') { - *Mc = 39.0; - } + // The Norway and Svalbard exceptions do NOT change the central meridian of + // the impacted zones (31V, 32V, 31X, 33X, 35X, 37X). if (zc>'M') { *N0 = 0.0; diff --git a/reference/grid-utm.csv b/reference/grid-utm.csv index 19d736ac6..657b4696f 100644 --- a/reference/grid-utm.csv +++ b/reference/grid-utm.csv @@ -24,3 +24,17 @@ No,UTM-Zone,UTM-Ch,UTM-East,UTM-North,Name,Altitude,Symbol,Date,Time 23,29,K,268668,7620784,"Wpt_tzplq3SA",13.0,"Waypoint",2008/08/23,18:15:08 24,57,S,456928,3682270,"Wpt_vhagfqH",10.0,"Waypoint",2008/08/23,18:14:24 25,40,V,590806,6323254,"Wpt_ZHNuvzhQ",51.0,"Waypoint",2008/08/23,18:15:42 +26,31,V,388456,6653097,"Wpt_31V_1",0.0,"Waypoint",2018/11/24,00:00:00 +27,31,V,444224,6651833,"Wpt_31V_2",0.0,"Waypoint",2018/11/24,00:00:00 +28,32,V,221289,6661953,"Wpt_32V_1",0.0,"Waypoint",2018/11/24,00:00:00 +29,32,V,611544,6653097,"Wpt_32V_2",0.0,"Waypoint",2018/11/24,00:00:00 +30,31,X,446000,8436100,"Wpt_31X_1",0.0,"Waypoint",2018/11/24,00:00:00 +31,31,X,634874,8440900,"Wpt_31X_2",0.0,"Waypoint",2018/11/24,00:00:00 +32,33,X,365126,8440900,"Wpt_33X_1",0.0,"Waypoint",2018/11/24,00:00:00 +33,33,X,634874,8440900,"Wpt_33X_2",0.0,"Waypoint",2018/11/24,00:00:00 +34,35,X,365126,8440900,"Wpt_35X_1",0.0,"Waypoint",2018/11/24,00:00:00 +35,35,X,634874,8440900,"Wpt_35X_2",0.0,"Waypoint",2018/11/24,00:00:00 +36,37,X,365126,8440900,"Wpt_37X_1",0.0,"Waypoint",2018/11/24,00:00:00 +37,37,X,554000,8436100,"Wpt_37X_2",0.0,"Waypoint",2018/11/24,00:00:00 +38,31,X,457406,8770704,"Wpt_31X_1",0.0,"Waypoint",2018/11/24,00:00:00 +39,31,X,472793,9216930,"Wpt_31X_2",0.0,"Waypoint",2018/11/24,00:00:00 diff --git a/reference/grid-utm~csv.gpx b/reference/grid-utm~csv.gpx index 9bfc263cb..37c6cc902 100644 --- a/reference/grid-utm~csv.gpx +++ b/reference/grid-utm~csv.gpx @@ -1,7 +1,7 @@ - + Wpt_12E7vrv @@ -196,4 +196,116 @@ Wpt_ZHNuvzhQ Waypoint + + 0.000 + + Wpt_31V_1 + Wpt_31V_1 + Wpt_31V_1 + Waypoint + + + 0.000 + + Wpt_31V_2 + Wpt_31V_2 + Wpt_31V_2 + Waypoint + + + 0.000 + + Wpt_32V_1 + Wpt_32V_1 + Wpt_32V_1 + Waypoint + + + 0.000 + + Wpt_32V_2 + Wpt_32V_2 + Wpt_32V_2 + Waypoint + + + 0.000 + + Wpt_31X_1 + Wpt_31X_1 + Wpt_31X_1 + Waypoint + + + 0.000 + + Wpt_31X_2 + Wpt_31X_2 + Wpt_31X_2 + Waypoint + + + 0.000 + + Wpt_33X_1 + Wpt_33X_1 + Wpt_33X_1 + Waypoint + + + 0.000 + + Wpt_33X_2 + Wpt_33X_2 + Wpt_33X_2 + Waypoint + + + 0.000 + + Wpt_35X_1 + Wpt_35X_1 + Wpt_35X_1 + Waypoint + + + 0.000 + + Wpt_35X_2 + Wpt_35X_2 + Wpt_35X_2 + Waypoint + + + 0.000 + + Wpt_37X_1 + Wpt_37X_1 + Wpt_37X_1 + Waypoint + + + 0.000 + + Wpt_37X_2 + Wpt_37X_2 + Wpt_37X_2 + Waypoint + + + 0.000 + + Wpt_31X_1 + Wpt_31X_1 + Wpt_31X_1 + Waypoint + + + 0.000 + + Wpt_31X_2 + Wpt_31X_2 + Wpt_31X_2 + Waypoint + diff --git a/reference/grid-utm~xscv.gpx b/reference/grid-utm~xscv.gpx index 6f8a86fbf..f62f860c9 100644 --- a/reference/grid-utm~xscv.gpx +++ b/reference/grid-utm~xscv.gpx @@ -1,7 +1,7 @@ - + "Wpt_12E7vrv" @@ -171,4 +171,102 @@ "Wpt_ZHNuvzhQ" "Wpt_ZHNuvzhQ" + + 0.000 + + "Wpt_31V_1" + "Wpt_31V_1" + "Wpt_31V_1" + + + 0.000 + + "Wpt_31V_2" + "Wpt_31V_2" + "Wpt_31V_2" + + + 0.000 + + "Wpt_32V_1" + "Wpt_32V_1" + "Wpt_32V_1" + + + 0.000 + + "Wpt_32V_2" + "Wpt_32V_2" + "Wpt_32V_2" + + + 0.000 + + "Wpt_31X_1" + "Wpt_31X_1" + "Wpt_31X_1" + + + 0.000 + + "Wpt_31X_2" + "Wpt_31X_2" + "Wpt_31X_2" + + + 0.000 + + "Wpt_33X_1" + "Wpt_33X_1" + "Wpt_33X_1" + + + 0.000 + + "Wpt_33X_2" + "Wpt_33X_2" + "Wpt_33X_2" + + + 0.000 + + "Wpt_35X_1" + "Wpt_35X_1" + "Wpt_35X_1" + + + 0.000 + + "Wpt_35X_2" + "Wpt_35X_2" + "Wpt_35X_2" + + + 0.000 + + "Wpt_37X_1" + "Wpt_37X_1" + "Wpt_37X_1" + + + 0.000 + + "Wpt_37X_2" + "Wpt_37X_2" + "Wpt_37X_2" + + + 0.000 + + "Wpt_31X_1" + "Wpt_31X_1" + "Wpt_31X_1" + + + 0.000 + + "Wpt_31X_2" + "Wpt_31X_2" + "Wpt_31X_2" +